﻿(function (wtm) {
    wtm.textbox_Render = function (para) {
        if (para.beforeMount.length > 0) {
            eval(para.beforeMount + '(para);');
        }

        //预处理url
        para.searchUrl = wtm.getUrl(para.searchUrl);
        para.triggerUrl = wtm.getUrl(para.triggerUrl);

        layui.autocomplete.render({
            elem: $('#' + para.id)[0],
            url: para.searchUrl,
            cache: false,
            template_val: '{{d.' + para.valueKey + '}}',
            template_txt: '{{d.' + para.textKey + '}}',
            onselect: function (data) {
                $('#' + para.id).val(data[para.valueKey]);

                data.triggerUrl = para.triggerUrl + '?id=' + data[para.valueKey];

                if (para.ChainChange.length > 0) {
                    if (eval(para.changeFunc + '(data)') == false) {
                        return;
                    }
                }

                if (para.triggerUrl.length > 0) {
                    wtm.ChainChange(data.triggerUrl, $(data.elem));
                }
            },
            time_limit: para.debounce
        });

        if (para.mounted.length > 0) {
            eval(para.mounted + '(para);');
        }
    };

   
})(wtm);